/**业务管理流程平台版本1.0,生成时间:2017-04-13 13:16:48**/
package com.xbdun.dao.bmp.mapper;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.DeleteProvider;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectKey;
import org.apache.ibatis.annotations.SelectProvider;

import com.xbdun.dao.bmp.entity.XbdunPowerRoleDepartDo;
import com.xbdun.dao.bmp.provider.PowerRoleDepartSqlProvider;


/**
 * 部门关联角色权限
 * @author 张国涛
 * @2017-04-13 13:16:48
 */
@Mapper
public interface PowerRoleDepartMapper{

	/**
	* @Title: addPowerRolesDepart
	* @Description 新增部门角色关联权限
	* @param orgCode		当前机构ID
	* @param roleDepartId	部门关联角色中间表ID
	* @param menusCode    	菜单编号
	 */
	@SelectProvider(type=PowerRoleDepartSqlProvider.class,method="addPowerRolesDepartSql")
	public void addPowerRolesDepart(@Param("orgCode")Long orgCode,@Param("orleDepartId")Long roleDepartId,@Param("menus")List<Long> menusCode);
	
	/**
	* @Title: delPowerRolesDepart
	* @Description 删除部门角色关联菜单
	* @param orgCode			机构编号
	* @param roleDepartId		部门角色中间表ID
	* @param menusCode    		菜单列表
	* @return void    返回类型
	 */
	@DeleteProvider(type=PowerRoleDepartSqlProvider.class,method="delPowerRolesDepartSql")
	public void delPowerRolesDepart(@Param("orgCode")Long orgCode,@Param("orleDepartId")Long roleDepartId,@Param("menus")List<Long> menusCode);
	//==============================================================================
	/**
	 * 根据主键获取对象
	 * @return
	 */
	@Select("SELECT * FROM xbdun_power_role_depart where id=#{id}")
	public XbdunPowerRoleDepartDo getXbdunPowerRoleDepartById(@Param("id")long id);
	
	/**
	 * 新增
	 * @param XbdunPowerRoleDepartDo 部门关联角色权限
	 */
	@Insert("INSERT INTO xbdun_power_role_depart(code,orgCode,orleDepartId) VALUES(#{a.code},#{a.orgCode},#{a.orleDepartId})")
	@SelectKey(statement="SELECT LAST_INSERT_ID() AS ID", before = false, keyProperty = "a.id", resultType = Long.class)
	public Long addXbdunPowerRoleDepart(@Param("a")XbdunPowerRoleDepartDo xbdunPowerRoleDepartDo);
	
	/**
	 * 判断是否存在,不为null则是存在
	 * @param param
	 * @return Long
	 */
	@SelectProvider(type=PowerRoleDepartSqlProvider.class,method="existSql")
	public int existXbdunPowerRoleDepart(@Param("param")Map<String,Object> param);

	/**
	* @Title: existItem
	* @Description	查看部门关联角色是否还存在子菜单
	* @param orleDepartId	关键中间表ID
	* @param orgCode		操作当前机构ID
	* @return int    返回类型
	 */
	@Select("SELECT COUNT(*) FROM xbdun_power_role_depart WHERE orleDepartId = ${orleDepartId} AND orgCode=${orgCode}")
	public int existItem(@Param("orleDepartId")Long orleDepartId,@Param("orgCode")long orgCode);

	/**
	* @Title: queryOrleDepartMenus
	* @Description	获取当前机构下部门关联的角色所有权限
	* @param orleDepartId	部门角色关联中间表ID
	* @param orgCode		当前机构ID
	* @return List<String>    返回类型
	 */
	@Select("SELECT CONCAT(code,'') FROM xbdun_power_role_depart WHERE orleDepartId = ${orleDepartId} AND orgCode=${orgCode} ORDER BY code ASC")
	public List<String> queryOrleDepartMenus(@Param("orleDepartId")Long orleDepartId,@Param("orgCode")long orgCode);
}